package com.cx.common.restful;

import lombok.AllArgsConstructor;
import lombok.Getter;


@Getter
@AllArgsConstructor
public enum ResultCode {

	FAIL(0, "失败"),
	SUCCESS(1, "成功"),

	/*权限错误码*/
	UNAUTHENTICATED(700,"认证失败(未登录,或token无效)"),
	UNAUTHENTICATED_MSG(701,"登录状态已变更，请重新登录！"),
	UNAUTHORIZED(702,"权限不足"),
	UNAUTHORIZED_MSG(703,"权限不足，请刷新页面或联系管理员！") ,

	TOKEN_IS_NULL(800, "token为空"),
	TOKEN_IS_EXPIRED(801, "token已过期"),
	TOKEN_IS_ERROR(802, "token错误"),


	/** 参数方面的异常错误码 */
	PARAM_NULL(1000,"参数为空"),
	PARAM_LESS(1001,"缺少参数"),
	PARAM_ERROR(1002,"非法参数"),
	PARAM_JSON_ERROR(1003, "参数Json序列化异常");


	private int code;

	private String message;

	public static ResultCode valueOf(int code) {
		for(ResultCode resultCode : values()) {
			if(code == resultCode.code) {
				return resultCode;
			}
		}
		return null;
	}

}
